import { Component } from '@angular/core';
import {  NavController, NavParams,ViewController } from 'ionic-angular';
import { PincodeController } from  'ionic2-pincode-input';
/**
 * Generated class for the PininputPage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */


@Component({
  selector: 'page-pininput',
  templateUrl: 'pininput.html',
})
export class PininputPage {
  public chooseType='handle';
  public code:any;
  public showArr=[
   {
     text:' 1.cnpm install ionic2-pincode-input --save',
     tips:'安装依赖'
    },{
      text:"2.import { PincodeInputModule } from  'ionic2-pincode-input';",
      tips:'添加到应用模块'
    }
  ];
  private handlePIN: (pincode: string) => Promise<any> = (pincode: string) => {
    if (pincode === '123456') {
      // Do something
      console.log('Too easy');
      return Promise.reject('');
    } else {
      // Do something
      return Promise.resolve();
    }
  };
  constructor(public navCtrl: NavController, public navParams: NavParams, public viewCtrl:ViewController,public pincodeCtrl:PincodeController) {
  }


  dismiss(){
    this.viewCtrl.dismiss();
  }
  openCode(){
    let pinCode =  this.pincodeCtrl.create({
      title:'Pincode',
      pinHandler: this.handlePIN
    });

    pinCode.present();

    pinCode.onDidDismiss( (code,status) => {

      if(status === 'done'){
        // 输入完成
        this.code = code;
        console.log(code)
      }else if (status === 'forgot'){
        // 忘记密码
      }

    })

  }
  
  segmentChanged(e){
    console.log(e)
    console.log(this.chooseType)
  }
  ionViewDidLoad() {
    console.log('ionViewDidLoad PininputPage');
  }

}
